package com.ys.web.pay.conrtoller;

import com.ys.utils.base.http.ResponseHandler;
import com.ys.utils.base.j2se.DateHandler;
import com.ys.utils.base.j2se.StringHandler;
import com.ys.utils.spring.properties.Config;
import com.ys.web.pay.service.StatisticalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ 名称:
 * @ 创建人: dhf
 * @ 参数： null
 * @ 创建时间: 2022/5/10
 * @ 修改人和其它信息
 * @ 返回值: 
 */
@RestController
@RequestMapping("/statistical")
public class StatisticalController {

    @Autowired
    private StatisticalService statisticalService;


    /**
     * @title getAllStatisticalType
     * @description 获取所有统计类型
     * @author quxinjun
     * @updateTime 2021/10/14 15:12
     * @return: java.lang.String
     */
    @PostMapping("/getAllStatisticalType")
    public String getAllStatisticalType() {
        List<Map<String, Object>> result = statisticalService.getAllStatisticalType();
        return ResponseHandler.list(result);
    }

    /**
     * @param uid 操作人id
     * @title getFlowByUserId
     * @description 获取对应类型的资金流水
     * @author quxinjun
     * @updateTime 2021/10/14 16:24
     * @return: java.lang.String
     */
    @PostMapping("/getFlowByUserId")
    public String getFlowByUserId(@RequestAttribute Long uid, String type,
                                  @RequestParam(defaultValue = "2") int payChannel,
                                  @RequestParam(defaultValue = "10") int pageSize,
                                  @RequestParam(defaultValue = "0") int pageNumber,
                                  String queryDate) {
        if (StringHandler.isEmpty(type)) {
            return ResponseHandler.error("500", "参数传递错误");
        }
        String dayTime = DateHandler.getDate(DateHandler.getDate(StringHandler.getInt(Config.pp.get("ys.del.data.select.day.number"),-4)))+" 00:00:00";
        Map<String, Object> result = statisticalService.getFlowByUserId(uid, type, payChannel,pageNumber, pageSize, queryDate,dayTime);
        return ResponseHandler.success(result);
    }

}
